/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package algorithm;

/**
 *
 * @author mwiatrowski
 */
import java.awt.Color;
import java.awt.image.BufferedImage;
import util.Utils;


public class AlgorithmImgDiff {
    private BufferedImage img1 = null;
    private BufferedImage img2 = null;
    
    public BufferedImage proces(BufferedImage imageNow, BufferedImage imagePrevious){
        
            img1 = Utils.deepCopy(imageNow);
            img2 = Utils.deepCopy(imagePrevious);

            int width1 = img1.getWidth();
            int width2 = img2.getWidth();
            int height1 = img1.getHeight();
            int height2 = img2.getHeight();

            BufferedImage out = new BufferedImage(img1.getWidth(), img1.getHeight(), BufferedImage.TYPE_3BYTE_BGR);

            if ((width1 != width2) || (height1 != height2)) {
              out=null;
              System.out.println("bład");
            }else{
            for (int i = 0; i < height1; i++) {
                for (int j = 0; j < width1; j++) {
                    int rgb1 = img1.getRGB(j, i);
                    int rgb2 = img2.getRGB(j, i);
                    int r1 = (rgb1 >> 16) & 0xff;
                    int g1 = (rgb1 >> 8) & 0xff;
                    int b1 = (rgb1) & 0xff;
                    int r2 = (rgb2 >> 16) & 0xff;
                    int g2 = (rgb2 >> 8) & 0xff;
                    int b2 = (rgb2) & 0xff;
                    int R = Math.abs(r2 - r1);
                    int G = Math.abs(g2 - g1);
                    int B = Math.abs(b2 - b1);
                    out.setRGB(j, i, new Color(R, G, B).getRGB());
                }
            }
            }
            return Utils.deepCopy(out);
        }
    
    public static void main(String args[]) {
       
    }
}